import { ref } from 'vue'
import { defineStore } from 'pinia'
export const useAppStore = defineStore(
  'app',
  () => {
    const token = ref('')
    let userInfo = ref({})
    const setToken = async (newToken) => {
      token.value = newToken
    }
    const setUserInfo = (newUserInfo) => {
      userInfo.value = newUserInfo
    }
    const getUserInfo = () => {
      return userInfo.value
    }
    const removeUserInfo = () => {
      userInfo.value = {}
    }
    const getToken = () => {
      return token.value
    }
    const removeToken = () => {
      token.value = ''
    }
    return {
      token,
      userInfo,
      setToken,
      getToken,
      removeUserInfo,
      removeToken,
      setUserInfo,
      getUserInfo
    }
  },
  {
    persist: true,
    storage: sessionStorage //修改存储位置
  }
)
export default useAppStore
